package com.tansun.easycare.rule.rulegroup.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.tansun.easycare.core.utils.ResponseTable;
import com.tansun.easycare.rule.common.Constant;
import com.tansun.easycare.rule.common.DataCache;
import com.tansun.easycare.rule.common.JsonMessage;
import com.tansun.easycare.rule.common.ResMessage;
import com.tansun.easycare.rule.common.RuleBaseController;
import com.tansun.easycare.rule.common.enums.RuleModelTypeFileEnum;
import com.tansun.easycare.rule.common.model.ResponseVO;
import com.tansun.easycare.rule.common.web.model.ProjectInfo;
import com.tansun.easycare.rule.datamodel.service.DataModelService;
import com.tansun.easycare.rule.exception.BizException;
import com.tansun.easycare.rule.rulegroup.entity.RuleEntry;
import com.tansun.easycare.rule.rulegroup.entity.RuleGroup;
import com.tansun.easycare.rule.rulegroup.entity.RuleGroupRef;
import com.tansun.easycare.rule.rulegroup.model.DelRuleInfo;
import com.tansun.easycare.rule.rulegroup.model.OldRuleGroupRefNew;
import com.tansun.easycare.rule.rulegroup.model.RuleEntryReq;
import com.tansun.easycare.rule.rulegroup.model.RuleGroupInfo;
import com.tansun.easycare.rule.rulegroup.model.RuleRefReq;
import com.tansun.easycare.rule.rulegroup.model.RuleSetDataInfo;
import com.tansun.easycare.rule.rulegroup.model.RuleSetVO;
import com.tansun.easycare.rule.rulegroup.model.SortInfo;
import com.tansun.easycare.rule.rulegroup.service.RuleEntryService;
import com.tansun.easycare.rule.rulegroup.service.RuleGroupRefService;
import com.tansun.easycare.rule.rulegroup.service.RuleGroupService;
import com.tansun.easycare.rule.rulegroup.service.impl.RuleGroupServiceImpl;
import com.tansun.easycare.rule.rulemange.entity.RuleManage;
import com.tansun.easycare.rule.rulemange.model.RuleManageVO;
import com.tansun.easycare.rule.rulemange.service.RuleManageService;
import com.tansun.easycare.rule.ruleproj.service.RuleProjectRankService;
import com.tansun.easycare.rule.ruleversion.entity.RuleVersioninfo;
import com.tansun.easycare.rule.ruleversion.service.RuleVersioninfoService;
import com.tansun.easycare.rule.utils.PageUtils;
import com.tansun.rule.common.RuleModelTypeEnum;
import com.tansun.rule.utils.LoggerManager;

@RestController
@RequestMapping(value = "/ruleProj/policyRuleGroup")
public class RuleGroupController extends RuleBaseController {

	private final Logger logger = LoggerFactory.getLogger(RuleGroupController.class);

    @Autowired
    private RuleManageService ruleManageService;

    @Autowired
    private RuleGroupService ruleGroupService;

    @Autowired
    private RuleGroupRefService ruleGroupRefService;

    @Autowired
    private RuleVersioninfoService ruleVersioninfoService;

    @Autowired
    private RuleEntryService ruleEntryService;

    @Autowired
    private DataModelService dataModelService;

    @Autowired
    private RuleProjectRankService ruleProjectRankService;

    /**
     * 政策规则集列表页面
     *
     * @param request   HttpServletRequest
     * @param response  HttpServletResponse
     * @param map       ModelMap
     * @param modelName "policyRuleGroup"
     * @param param     查询参数
     * @return JSP路径
     */
    @RequestMapping("index")
    public ResponseTable<RuleManageVO> index(HttpServletRequest request, HttpServletResponse response, @RequestBody RuleManageVO param, ModelMap map) throws Exception {
    	//ruleGroupUtils.initRank(this.getCurrProjectCode(),param.getRankRelationId());
    	if(StringUtils.isEmpty(param.getProjectCode())) {
    		param.setProjectCode(this.getCurrProjectCode());
    	}
        param.setModelType(RuleModelTypeEnum.PolicyRuleGroup.code);
        PageInfo<RuleManageVO> pageInfo = ruleManageService.findRuleManageVO(param.getPage(), param);
        ResponseTable<RuleManageVO> resVo = new  ResponseTable<RuleManageVO>(pageInfo);
        return resVo;
    }
    //--- 以上是vue规则集使用的方法，查询列表页面

    @RequestMapping("precondition")
    public String precondition() throws Exception {
        return "rule/rulegroup/ruleset/precondition";
    }
    /**
     * 添加规则集
     *
     * @param request  HttpServletRequest
     * @param response HttpServletResponse
     * @param rcv      规则集信息
     * @return 添加规则结果信息
     */
    @RequestMapping("addCollectionVo")
    public @ResponseBody ResponseVO addCollectionVo(HttpServletRequest request, HttpServletResponse response, @RequestBody RuleManage rcv) throws Exception {
    	ResponseVO res = new ResponseVO();
    	res.setStatus(ResponseVO.OK);
        try {
            Integer num = this.ruleManageService.countListFindName(rcv, rcv.getModelType());
            if (num != null && num>0) {
                res.setStatus(ResponseVO.ERROR);
                res.setDescription("变量名称重复，请使用其他有效名称");
                return res;
            }
            res.setDescription("添加成功");
            rcv.setModelType(rcv.getModelType());
            if(StringUtils.isEmpty(rcv.getProjectCode())) {
            	rcv.setProjectCode(this.getCurrProjectCode());
            }
            rcv.setCountSalience(Constant.FIRST_SALIENCE);
            ruleManageService.saveOrUpdate(rcv);
    		//新增第一个规则的时候初始化内置变量
            dataModelService.saveOrUpdateBuiltinParam(rcv.getCode(),rcv.getName(), rcv.getModelType(), rcv.getProjectCode(), rcv.getCreateBy());
        } catch (Exception e) {
        	String error = ExceptionUtils.getStackTrace(e);
            LoggerManager.error(error, e, this.getClass());
            LoggerManager.error("", e, this.getClass());
            String msg = "操作失败！";
            if (e instanceof BizException) {
                BizException biz = (BizException) e;
                msg = biz.getMessage();
            }
            res.setDesDetail(error);
            res.setDescription(msg);
            res.setStatus(ResponseVO.ERROR);
        }
        return res;
    }
    //--- 以上是vue规则集使用的方法，添加新增修改规则集

    /**
     * 添加规则条目
     *
     * @param request  HttpServletRequest
     * @param response HttpServletResponse
     * @param rcv      规则集信息
     * @return 添加规则结果信息
     */
    @RequestMapping("addRuleEntryVo")
    public @ResponseBody ResponseVO addRuleEntryVo(HttpServletRequest request, HttpServletResponse response, @RequestBody RuleEntry ruleEntry) throws Exception {
    	ResponseVO res = new ResponseVO();
    	res.setStatus(ResponseVO.OK);
    	res.setDescription("添加成功");
        try {
    		String manageId = ruleEntry.getManageId();
        	RuleManage ruleManage = this.ruleManageService.get(manageId);
            String oldVersion = ruleManage.getVersion();
            if(!oldVersion.contains("_modify")) {
            	ruleManage.setStatus(Constant.RULE_STATUS_NORMAL);
            	ruleManage.initVersion(ruleManage.getIsTemp());
                ruleManage.setVersion(ruleManage.getVersion()+"_modify");
                OldRuleGroupRefNew oldnew= ruleGroupService.copyComplexRuleGroup(ruleManage.getId(), oldVersion,ruleManage.getVersion());
                Map<String,String> old2newId = oldnew.getOld2EntryNewId();
                if(old2newId!=null && old2newId.containsKey(ruleEntry.getId())) {
                	ruleEntry.setId(old2newId.get(ruleEntry.getId()));
                }
                ruleEntry.setVersion(ruleManage.getVersion());
                this.ruleManageService.save(ruleManage);
            }
        	ruleEntryService.saveOrUpdate(ruleEntry);
        	res.setData(ruleManage);
        } catch (Exception e) {
        	String error = ExceptionUtils.getStackTrace(e);
            LoggerManager.error(error, e, this.getClass());
            String msg = "操作失败！";
            if (e instanceof BizException) {
                BizException biz = (BizException) e;
                msg = biz.getMessage();
            }
            res.setDesDetail(error);
            res.setDescription(msg);
            res.setStatus(ResponseVO.ERROR);
        }
        return res;
    }
    //--- 以上是vue规则集使用的方法，添加新增条目
    /**
     * 修改规则集
     *
     * @param request  HttpServletRequest
     * @param response HttpServletResponse
     * @param rcv      规则集Vo对象
     * @return 修改结果信息
     */
    @RequestMapping("updateCollectionVo")
    public @ResponseBody ResponseVO updateCollectionVo(@ModelAttribute RuleManage rcv) throws Exception {
    	ResponseVO res = new ResponseVO();
    	res.setStatus(ResponseVO.OK);
    	res.setDescription("更新成功");
    	try {
        	RuleManage rm = this.ruleManageService.get(rcv.getId());
            dataModelService.saveOrUpdateBuiltinParam(rm.getCode(),rcv.getName(), rm.getModelType(), rm.getProjectCode(),rcv.getCreateBy());
            this.ruleManageService.saveOrUpdate(rcv);
        } catch (Exception e) {
        	String error = ExceptionUtils.getStackTrace(e);
            LoggerManager.error(error, e, this.getClass());
            res.setDesDetail(error);
            res.setDescription(e.getMessage());
            res.setStatus(ResponseVO.ERROR);
        }
        return res;
    }
   //--- 以上是vue规则集使用的方法，添加修改规则集

    /**
     * 打开规则集，进入普通条目
     *
     * @param ruleEntryReq  RuleEntryReq
     * @return ResponseTable
     */
    @RequestMapping("openGeneralRuleEntry")
    public ResponseTable<RuleEntry> openGeneralRuleEntry(@RequestBody RuleEntryReq ruleEntryReq) throws Exception {
    	return this.ruleGroupService.getEntryInfoByReq(ruleEntryReq, RuleEntry.GROUPTYPE_GENERAL_0);
    }
    //--- 以上是vue规则集使用的方法，打开规则集，进入普通条目

    /**
     * 打开规则集，进入互斥条目
     *
     * @param ruleEntryReq  RuleEntryReq
     * @return ResponseTable
     */
    @RequestMapping("openMutualRuleEntry")
    public ResponseTable<RuleEntry> openMutualRuleEntry(@RequestBody RuleEntryReq ruleEntryReq) throws Exception {
    	return this.ruleGroupService.getEntryInfoByReq(ruleEntryReq, RuleEntry.GROUPTYPE_MUTEXCLU_1);
    }
    //--- 以上是vue规则集使用的方法，打开规则集，进入互斥条目

    /**
     * 更新规则条目页面
     *
     * @param map      ModelMap
     * @param version  规则集版本
     * @param manageId 规则集manageId
     * @param entryId       规则条目Id
     * @param type 	修改 或者显示
     * @return JSP路径
     */
    @RequestMapping("updateRuleEntryPage")
    public ResponseTable<RuleGroup> updateRuleEntryPage(@RequestBody RuleGroupInfo req) throws Exception {
        return ruleGroupService.openRuleEntryView(req);
    }
    //--- 以上是vue规则集使用的方法，打开条目

    /**
     * 打开规则集，仅查看
     *
     * @param map      ModelMap
     * @param code     规则项编码
     * @param type     规则集类别： 普通 规则集 政策规则集
     * @return JSP路径
     */
    @RequestMapping("openRuleSet")
    public String openRuleSetPage(String id, String version, ModelMap map, String temp,String rankRelationId) throws Exception {
        if (StringUtils.isEmpty(id)) {
            throw new BizException("ID为空");
        }
      //修复id带版本号的缺陷 如： PRG00000000001_v20.00
        if(id.contains("_")){
            final String[] ids = id.split("_");
            id=ids[0];
        }
        RuleManageVO ruleManage = new RuleManageVO();
        Map<String, Object> parmMap = new HashMap<String, Object>();
        parmMap.put("id", id);
        List<RuleManageVO> vList = this.ruleManageService.findRuleManageVO(parmMap);
        if (vList == null || vList.size() == 0) {
        	RuleManage tmp = ruleManageService.findByCode(id, this.getCurrProjectCode());
        	if(tmp==null){
        		  throw new BizException("");
        	}else{
        		BeanUtils.copyProperties(ruleManage, tmp);
        	}
        }else{
        	ruleManage = vList.get(0);
        }
        map.put("ruleManageVO", ruleManage);
        RuleGroup ruleGroup = new RuleGroup();
        ruleGroup.setManageId(ruleManage.getId());
        if (StringUtils.isEmpty(version)) {
            ruleGroup.setVersion(ruleManage.getVersion());
            if("1".equals(temp)) {
            	ruleGroup.setVersion(ruleManage.getActiveVersion());
    		}
        } else {
            ruleGroup.setVersion(version);
        }
        List<RuleGroup> ruleList = this.ruleGroupRefService.findRuleGroupList(ruleGroup);
        map.put("ruleList", ruleList);
        map.put("code", ruleManage.getCode());
        if (!StringUtils.isEmpty(version)) {
            map.put("version", version);
        }
        //其他人已经锁定
        boolean otherlock = false;
//        String currentUser = UserUtils.getUser().getLoginName();
//        if (StringUtils.isNotBlank(ruleManage.getLocker()) && !currentUser.equals(ruleManage.getLocker())) {
//            otherlock = true;
//        }
        boolean unlock = false;
        if (StringUtils.isBlank(ruleManage.getLocker())) {
            unlock = true;
        }
        //未授权
        boolean authority = false;
        //if (ruleManage.getUsers()!=null && ruleManage.getUsers().indexOf(currentUser + ";") < 0) {
		if(ruleManage.getLocker()!=null && ruleManage.getLocker() == ""){
               authority = true;
        }
        if (otherlock || authority || unlock) {
            map.put("authview", "hide");
        } else {
            map.put("authview", "show");
        }
        map.put("rankRelationId", rankRelationId);
        return "rule/rulegroup/ruleset/ruleSetList";
    }



    /**
     * 引用规则
     * @param ruleRefVOPage
     * @param ruleName
     * @return
     * @throws Exception
     */
	@RequestMapping("generalRuleReference")
    public ResponseTable<RuleManage> generalRuleReference(@RequestBody RuleRefReq ruleRefReq) throws Exception {
		String projectCode = ruleRefReq.getProjectCode();
		if(StringUtils.isEmpty(projectCode)) {
			ruleRefReq.setProjectCode(this.getCurrProjectCode());
		}
    	String ruleName = ruleRefReq.getRuleName();
    	List<String> ruleIds = ruleRefReq.getIds();
    	String rankRelationId = ruleRefReq.getRankRelationId();
    	List<String> ids = ruleProjectRankService.findIdsByRecursion(rankRelationId,RuleModelTypeFileEnum.GeneralRule.fileName);
    	List<RuleSetVO> groups = this.ruleGroupService.generalRuleSetVOList(projectCode);
    	List<RuleManage> needRef = new ArrayList<>();


    	for(RuleSetVO ruleSetVO:groups) {
			String rName = ruleSetVO.getRuleManage().getName();
			String rankId = ruleSetVO.getRuleManage().getRankRelationId();
			RuleGroup rg = ruleSetVO.getRules().get(0);
			if(RuleGroupServiceImpl.isFilter) {
	    		if( ids.contains(rankId) && !ruleIds.contains(rg.getId()) &&
	        			(	StringUtils.isEmpty(ruleName) ||
	        					(StringUtils.isNotEmpty(ruleName) && rName.contains(ruleName)))) {
	        			needRef.add(ruleSetVO.getRuleManage());
	        	}
			}else {
	    		if( !ruleIds.contains(rg.getId()) &&
	        			(	StringUtils.isEmpty(ruleName) ||
	        					(StringUtils.isNotEmpty(ruleName) && rName.contains(ruleName)))) {
	        			needRef.add(ruleSetVO.getRuleManage());
	        	}
			}

    	}
    	PageInfo<RuleManage> pageInfo = PageUtils.createSimglePageInfo(needRef,ruleRefReq);
    	ResponseTable<RuleManage> res = new ResponseTable<>(pageInfo);
        return res;
    }

    /**
     * 新增规则页面
     *
     * @param map      ModelMap
     * @param code     规则项编码
     * @param type     规则集类别： 普通 规则集 政策规则集
     * @return JSP路径
     */
    @RequestMapping("newRuleItemPage")
    public String newRuleItemPage(ModelMap map, String manageId,String entryId,String entryCode,String rankRelationId) throws Exception {
        map.put("manageId", manageId);
        map.put("entryId", entryId);
        map.put("entryCode", entryCode);
        RuleGroup rv = new RuleGroup();
        rv.setTxtType("formatObj");
        rv.setEnabled("on");
        map.put("operType", "add");
        map.put("rv", rv);
        map.put("type", RuleModelTypeEnum.PolicyRuleGroup.code);
        map.put("projectCode", this.getCurrProjectCode());
        map.put("rankRelationId", rankRelationId);
        return "rule/rulegroup/ruleset/newRuleItem";
    }


    /**
     * 更新规则页面
     *
     * @param map      ModelMap
     * @param code     规则项编码
     * @param type     规则集类别： 普通 规则集 政策规则集
     * @param id       规则项Id
     * @return JSP路径
     */
    @RequestMapping("updateRuleItemPage")
    public String updateRuleItemPage(ModelMap map, String type, String id,String refId,String manageId,String rankRelationId) throws Exception {
        RuleGroup rv = this.ruleGroupService.get(id);
        if ("show".equals(type)) {
            map.put("operType", "show");
        } else {
            map.put("operType", "edit");
        }
        RuleGroupRef ruleGroupref = new RuleGroupRef();
        ruleGroupref.setRuleId(id);
        ruleGroupref.setId(refId);
        ruleGroupref.setManageId(manageId);
        ruleGroupref = this.ruleGroupRefService.get(ruleGroupref);
        RuleEntry entry = this.ruleEntryService.get(ruleGroupref.getEntryId());
        map.put("manageId", manageId);
        map.put("entryId", entry.getId());
        map.put("entryCode", entry.getEntryCode());
        map.put("ruleGroupId", id);
        map.put("rv", rv);
        map.put("refId", refId);
        map.put("projectCode", this.getCurrProjectCode());
        map.put("rankRelationId", rankRelationId);
        return "rule/rulegroup/ruleset/newRuleItem";
    }

    /**
     * 获取编写规则集的配置元数据，包括包括数据模型，操作符等
     *
     * @param dataTarget 编写规则所需的数据目标 包括数据模型，操作符号等等
     */
    @RequestMapping("ruleSetEditJsonData")
    public ResponseVO ruleSetEditJsonData(@RequestBody  RuleSetDataInfo ruleSetData) throws Exception {
    	ResponseVO  res  = new  ResponseVO();
        String jsondata = this.ruleGroupService.getRuleSetEditJson(ruleSetData);
        res.setData(jsondata);
        return res;
    }
    /**
     * 新建
     * @param request
     * @param ruleGroup
     * @param map
     * @return
     * @throws Exception
     */
    @RequestMapping("newRuleItmeAction")
    public @ResponseBody
    ResMessage newRuleItmeAction(HttpServletRequest request, @RequestBody RuleGroup ruleGroup, ModelMap map) throws Exception {
        ResMessage res = new ResMessage("success", "添加成功！");
        try {
            this.ruleGroupService.saveOrUpdate(ruleGroup);
        } catch (Exception e) {
            res.setCode("fail");
            res.setMsg("规则名称重复！");
            logger.error(e.getMessage(), e);
        }

        return res;
    }

    /**
     * 版本管理方法： 保存规则集到小版本
     *
     * @param code     规则项编码
     * @param type     规则集类别： 普通 规则集 政策规则集
     * @return 版本更新结果
     */
    @RequestMapping("saveRuleEnterySetVo")
    public @ResponseBody ResponseVO saveRuleEnterySetVo(@RequestBody RuleGroupInfo ruleGroupInfo) throws Exception {
    	ResponseVO res = new ResponseVO();
    	res.setStatus(ResponseVO.OK);
    	try {
        	this.ruleGroupService.saveOrUpdateRuleGroup(ruleGroupInfo.getManageId());
        } catch (Exception e) {
        	String error = ExceptionUtils.getStackTrace(e);
        	logger.error(error, e);
        	res.setStatus(ResponseVO.ERROR);
        	res.setDescription(e.getMessage());
        	res.setDesDetail(error);
        }
        return res;
    }

    /**
     * 保存单一条目中的规则内容，主要将权重和优先级保存到rule_roup_ref关联表及条目信息
     *
     * @param map      ModelMap
     * @param code     规则项编码
     * @param type     规则集类别： 普通 规则集 政策规则集
     * @return 版本更新结果
     */
    @RequestMapping("saveRuleEntryVo")
    public @ResponseBody ResponseVO saveRuleEntryVo(@RequestBody RuleSetVO ruleSetVO) throws Exception {
    	ResponseVO res = new ResponseVO();
    	res.setStatus(ResponseVO.OK);
    	res.setDescription("success");
    	try {
        	RuleEntry ruleEntry0 = ruleSetVO.getRuleEntry();
        	RuleEntry ruleEntry = this.ruleEntryService.get(ruleEntry0);
        	ruleEntry.setConditions(ruleEntry0.getConditions());
        	ruleEntry.setEntryName(ruleEntry0.getEntryName());
        	ruleEntry.setRuleNames(ruleEntry0.getRuleNames());
        	ruleEntry.setAccessMode(ruleEntry0.getAccessMode());
    		String manageId = ruleEntry.getManageId();
        	RuleManage ruleManage = this.ruleManageService.get(manageId);
            String oldVersion = ruleManage.getVersion();
            if(!oldVersion.contains("_modify")) {
            	ruleManage.setStatus(Constant.RULE_STATUS_NORMAL);
            	ruleManage.initVersion(ruleManage.getIsTemp());
                ruleManage.setVersion(ruleManage.getVersion()+"_modify");
                OldRuleGroupRefNew oldnew= ruleGroupService.copyComplexRuleGroup(ruleManage.getId(), oldVersion,ruleManage.getVersion());
                Map<String,String> old2newId = oldnew.getOld2EntryNewId();
                if(old2newId!=null && old2newId.containsKey(ruleEntry.getId())) {
                	ruleEntry.setId(old2newId.get(ruleEntry.getId()));
                }
                ruleEntry.setVersion(ruleManage.getVersion());
                this.ruleManageService.save(ruleManage);
                RuleGroupRef returnData = new RuleGroupRef();
                returnData.setVersion(ruleManage.getVersion());
                returnData.setEntryId(ruleEntry.getId());
               	res.setData(returnData);
            }
        	this.ruleEntryService.saveOrUpdate(ruleEntry);
        	this.ruleEntryService.saveRuleEntryRef(ruleSetVO.getRules());
        } catch (Exception e) {
        	String error = ExceptionUtils.getStackTrace(e);
        	logger.error(error, e);
        	res.setStatus(ResponseVO.ERROR);
        	res.setDescription(e.getMessage());
        	res.setDesDetail(error);
        }
        return res;
    }


    /**
     * 规则条目内部规则的排序
     *
     * @param request  HttpServletRequest
     * @param response HttpServletResponse
     * @param map      ModelMap
     * @param code     规则项编码
     * @param type     规则集类别： 普通 规则集 政策规则集
     * @return 排序结果信息
     */
    @RequestMapping("salienceEntrySort")
    public @ResponseBody
    ResponseVO salienceEntrySort(@RequestBody SortInfo sortinfo) throws Exception {
    	ResponseVO res = new ResponseVO();
    	res.setStatus(ResponseVO.OK);
    	String manageId = sortinfo.getManageId();
    	String entryId1 = sortinfo.getFirstId();
    	String entryId2 = sortinfo.getSecondId();
    	String shiftType = sortinfo.getShiftType();
        RuleManage ruleManage = this.ruleManageService.get(manageId);
    	String version = ruleManage.getVersion();
    	if(!version.contains("_modify")){
    		ruleManage.setStatus(Constant.RULE_STATUS_NORMAL);
        	ruleManage.initVersion(ruleManage.getIsTemp());
            ruleManage.setVersion(ruleManage.getVersion()+"_modify");
            OldRuleGroupRefNew oldNew = ruleGroupService.copyComplexRuleGroup(ruleManage.getId(), version,ruleManage.getVersion());
            Map<String,String> old2newId = oldNew.getOld2EntryNewId();
            if(old2newId!=null) {
            	if(old2newId.containsKey(entryId1)){
            		entryId1 = old2newId.get(entryId1);
            	}
            	if(old2newId.containsKey(entryId2)){
            		entryId2 = old2newId.get(entryId2);
            	}
            }
            this.ruleManageService.save(ruleManage);
            res.setData(ruleManage);
    	}
        this.ruleEntryService.shiftSort(ruleManage, entryId1, entryId2, shiftType);
        return res;
    }
    // --- 以上是vue 引用规则条目顺序切换
    /**
     * 简易规则集内部规则的排序
     *
     * @param request  HttpServletRequest
     * @param response HttpServletResponse
     * @param map      ModelMap
     * @param code     规则项编码
     * @param type     规则集类别： 普通 规则集 政策规则集
     * @return 排序结果信息
     */
    @RequestMapping("salienceSort")
    public @ResponseBody ResponseVO salienceSort(@RequestBody SortInfo sortinfo) throws Exception {
        ResponseVO res = new ResponseVO();
        res.setStatus(ResponseVO.OK);
        res.setDescription("success");
    	String manageId = sortinfo.getManageId();
    	String refId1 = sortinfo.getFirstId();
    	String refId2 = sortinfo.getSecondId();
    	String shiftType = sortinfo.getShiftType();
        RuleManage ruleManage = this.ruleManageService.get(manageId);
    	String version = ruleManage.getVersion();
    	if(!version.contains("_modify")){
    		ruleManage.setStatus(Constant.RULE_STATUS_NORMAL);
        	ruleManage.initVersion(ruleManage.getIsTemp());
            ruleManage.setVersion(ruleManage.getVersion()+"_modify");
            OldRuleGroupRefNew oldNew = ruleGroupService.copyComplexRuleGroup(ruleManage.getId(), version,ruleManage.getVersion());
            Map<String,String> old2newId = oldNew.getOld2RefNewId();
            if(old2newId!=null) {
            	if(old2newId.containsKey(refId1)){
            		refId1 = old2newId.get(refId1);
            	}
            	if(old2newId.containsKey(refId2)){
            		refId2 = old2newId.get(refId2);
            	}
            }
            this.ruleManageService.save(ruleManage);
            res.setData(ruleManage);
    	}
        this.ruleGroupRefService.shiftSort(ruleManage, refId1, refId2, null);
        return res;
    }

    /**
     * 规则集合编译 生成Drl文件
     *
     * @param ruleGroupInfo 规则集信息 主要是manageId
     * @param type     规则集类别： 普通 规则集 政策规则集
     * @return 编译结果信息
     */
    @RequestMapping("compileRuleDrl")
    public @ResponseBody ResponseVO compileRuleDrl(@RequestBody RuleGroupInfo ruleGroupInfo) throws Exception {
        ResponseVO res = new ResponseVO();
        res.setStatus(ResponseVO.ERROR);
        try {
        	String message = this.ruleGroupService.compileDrl(ruleGroupInfo.getManageId());
        	if("编译成功".equals(message)) {
        		res.setStatus(ResponseVO.OK);
        	}
        	res.setDescription(message);
        	res.setDesDetail(message);
        } catch (BizException e) {
        	String error = ExceptionUtils.getRootCauseMessage(e);
        	logger.error(error);
        	res.setDescription(e.getMessage());
        	res.setDesDetail(error);
        }
        return res;
    }

    /**
     * 删除规则条目
     *
     * @param request  HttpServletRequest
     * @param response HttpServletResponse
     * @param manageId     规则项编码
     * @param entryId       规则条目Id
     * @return 删除结果信息
     */
    @RequestMapping("delRuleEntry")
    public @ResponseBody ResponseVO delRuleEntry(@RequestBody DelRuleInfo delRuleInfo) throws Exception {
    	//删除关联关系，不删除其本身
        ResponseVO res = new ResponseVO();
    	String entryId = delRuleInfo.getEntryId();
    	String manageId = delRuleInfo.getManageId();
    	RuleManage ruleManage = ruleManageService.get(manageId);
    	String version = ruleManage.getVersion();
    	if(!version.contains("_modify")){
    		ruleManage.setStatus(Constant.RULE_STATUS_NORMAL);
        	ruleManage.initVersion(ruleManage.getIsTemp());
            ruleManage.setVersion(ruleManage.getVersion()+"_modify");
            OldRuleGroupRefNew oldNew = ruleGroupService.copyComplexRuleGroup(ruleManage.getId(), version,ruleManage.getVersion());
            Map<String,String> old2newId = oldNew.getOld2EntryNewId();
            if(old2newId!=null && old2newId.containsKey(entryId)) {
            	entryId = old2newId.get(entryId);
            }
            this.ruleManageService.save(ruleManage);
            res.setData(ruleManage);
    	}
        RuleEntry ruleEntry = new RuleEntry();
        ruleEntry.setId(entryId);
        ruleEntry.setManageId(manageId);
        ruleEntry = this.ruleEntryService.findList(ruleEntry).get(0);
        this.dataModelService.deleteEntryBuitineParam(ruleManage.getCode(), ruleEntry.getEntryCode(), ruleManage.getName(), ruleEntry.getEntryName(), ruleManage.getProjectCode());
        this.ruleEntryService.delete(ruleEntry);

        RuleGroupRef ruleGroupRef = new RuleGroupRef();
        ruleGroupRef.setEntryId(entryId);
        ruleGroupRef.setManageId(manageId);
        List<RuleGroupRef> ruleRefs = this.ruleGroupRefService.findList(ruleGroupRef);
        for(RuleGroupRef ref:ruleRefs) {
        	this.ruleGroupRefService.delete(ref);
        }

        res.setStatus(ResponseVO.OK);
        return res;
    }
    // --- 以上是vue 规则条目删除
    /**
     * 修改规则集
     *
     * @param request  HttpServletRequest
     * @param response HttpServletResponse
     * @param map      ModelMap
     * @param code     规则项编码
     * @param type     规则集类别： 普通 规则集 政策规则集
     * @param id       规则项Id
     * @return 删除结果信息
     */
    @RequestMapping("delRuleVo")
    public ResponseVO delRuleVo(@RequestBody DelRuleInfo delRuleInfo) throws Exception {
        ResponseVO res = new ResponseVO();
    	String id = delRuleInfo.getId();//规则manageId
    	String entryId = delRuleInfo.getEntryId();//条目id
    	String refId = delRuleInfo.getRefId();//关联id
    	String manageId = delRuleInfo.getManageId();
    	String projectCode = delRuleInfo.getProjectCode();
    	RuleManage rm = this.ruleManageService.get(id);
    	RuleManage ruleGroupRM = this.ruleManageService.get(manageId);
    	String version = ruleGroupRM.getVersion();
    	//删除关联关系，不删除其本身
    	if( StringUtils.isNotEmpty(entryId) ) {
	    	if(!version.contains("_modify")){
	    		ruleGroupRM.setStatus(Constant.RULE_STATUS_NORMAL);
	    		ruleGroupRM.initVersion(ruleGroupRM.getIsTemp());
	    		ruleGroupRM.setVersion(ruleGroupRM.getVersion()+"_modify");
	            OldRuleGroupRefNew oldNew = ruleGroupService.copyComplexRuleGroup(manageId, version,ruleGroupRM.getVersion());
	            Map<String,String> old2newId = oldNew.getOld2EntryNewId();
	            if(old2newId!=null && old2newId.containsKey(entryId)) {
	            	entryId = old2newId.get(entryId);
	            }
	            Map<String,String> old2refnewId = oldNew.getOld2RefNewId();
	            if(old2refnewId!=null && old2refnewId.containsKey(refId)) {
	            	refId = old2refnewId.get(refId);
	            }
	            this.ruleManageService.save(ruleGroupRM);
	    	}
	    	RuleEntry ruleEntry = this.ruleEntryService.get(entryId);

	    	String ruleDelete = rm.getName();
	    	String ruleNames = ruleEntry.getRuleNames();
	    	if(StringUtils.isNotEmpty(ruleNames)) {
		    	int index = ruleNames.indexOf(ruleDelete);
		    	if( index != -1) {
		    		String newNames = "";
		    		if(ruleDelete.length() != ruleNames.length()) {
			    		int end = index+ruleDelete.length();
			    		if( index == 0 ) {
			    			end++;
			    		}else {
			    			index--;
			    		}
				    	newNames = ruleNames.substring(0, index)+ruleNames.substring(end);
		    		}
			    	ruleEntry.setRuleNames(newNames);
			    	this.ruleEntryService.saveOrUpdate(ruleEntry);
		    	}
	    	}
	        RuleGroupRef ruleGroupRef = new RuleGroupRef();
	        ruleGroupRef.setId(refId);
	        ruleGroupRef.setRuleId(id);
	        ruleGroupRef.setEntryId(entryId);
	        ruleGroupRef.setManageId(manageId);
	        ruleGroupRef.setVersion(ruleGroupRM.getVersion());
	        this.ruleGroupRefService.delete(ruleGroupRef);
    	}else if(!version.contains("_modify")){
    		ruleGroupRM.setStatus(Constant.RULE_STATUS_NORMAL);
    		ruleGroupRM.initVersion(ruleGroupRM.getIsTemp());
    		ruleGroupRM.setVersion(ruleGroupRM.getVersion()+"_modify");

            RuleGroupRef refCon = new RuleGroupRef();
            refCon.setManageId(ruleGroupRM.getId());
            refCon.setVersion(version);
            List<RuleGroupRef> ruleGroupRefs =  ruleGroupRefService.findList(refCon);
            RuleGroupRef target = null;
            for(RuleGroupRef ref:ruleGroupRefs) {
            	if(ref.getId().equals(refId)) {
            		target = ref;
            	}
            	ref.setId(null);
            	ref.setVersion(ruleGroupRM.getVersion());
            }
            ruleGroupRefs.remove(target);
            this.ruleGroupRefService.insertBatch(ruleGroupRefs);
            this.ruleManageService.save(ruleGroupRM);
    	}else {
	        RuleGroupRef ruleGroupRef = new RuleGroupRef();
	        ruleGroupRef.setId(refId);
	        ruleGroupRef.setRuleId(id);
	        ruleGroupRef.setEntryId(entryId);
	        ruleGroupRef.setManageId(manageId);
	        this.ruleGroupRefService.delete(ruleGroupRef);
    	}
        DataCache.ruleRefEntryGroupChange(projectCode);//清理缓存
        RuleGroupRef returnData = new RuleGroupRef();
        returnData.setVersion(ruleGroupRM.getVersion());
        returnData.setEntryId(entryId);
       	res.setData(returnData);
        res.setStatus(ResponseVO.OK);
        return res;
    }
    // --- 以上是vue 规则集中条目引用的规则删除

    /**
     * 通过转换器将页面配置转换成Drl文本 show rule item drl
     *
     * @param request  HttpServletRequest
     * @param response HttpServletResponse
     * @param map      ModelMap
     * @return Drl文本
     */
    @RequestMapping("showRuleItmeDrl")
    public @ResponseBody
    ResMessage showRuleItmeDrl(HttpServletRequest request, HttpServletResponse response, @RequestBody RuleSetVO ruleSetVO) throws Exception {
        ResMessage res = new ResMessage();
        String manageId = ruleSetVO.getRuleManage().getId();
        if (StringUtils.isEmpty(manageId)) {
            ruleSetVO.getRuleManage().setCode(this.ruleManageService.generalCodeByType(RuleModelTypeEnum.PolicyRuleGroup.code, this.getCurrProjectCode()));
            ruleSetVO.getRuleManage().setModelType(RuleModelTypeEnum.PolicyRuleGroup.code);
            ruleSetVO.getRuleManage().setVersion("v0.01");
        } else {
            ruleSetVO.setRuleManage(this.ruleManageService.get(manageId));

        }
        String drl = this.ruleGroupService.showRuleDrl(ruleSetVO);
        res.setCode("success");
        res.setMsg(drl);
        return res;
    }


    /**
     * 通过转换器将页面配置转换成java文本 show rule item java
     *
     * @param request  HttpServletRequest
     * @param response HttpServletResponse
     * @param map      ModelMap
     * @return Java文本
     */
    @RequestMapping("showRuleItmeJava")
    public @ResponseBody
    ResMessage showRuleItmeJava(@RequestBody RuleSetVO ruleSetVO) throws Exception {
        ResMessage res = new ResMessage();
        String manageId = ruleSetVO.getRuleManage().getId();
        if (StringUtils.isEmpty(manageId)) {
            ruleSetVO.getRuleManage().setProjectCode(getCurrProjectCode());
            ruleSetVO.getRuleManage().setCode(this.ruleManageService.generalCodeByType(RuleModelTypeEnum.GeneralRule.code, this.getCurrProjectCode()));
            ruleSetVO.getRuleManage().setModelType(RuleModelTypeEnum.GeneralRule.code);
            ruleSetVO.getRuleManage().setVersion("v0.01");
        } else {
            ruleSetVO.setRuleManage(this.ruleManageService.get(manageId));

        }
        ruleSetVO.getRuleManage().setProjectCode(this.getCurrProjectCode());
        String javacode = this.ruleGroupService.showRuleJava(ruleSetVO);
        res.setCode("success");
        res.setMsg(javacode);
        return res;
    }

    /**
     * 从普通规则中批量添加规则
     *
     * @param request     HttpServletRequest
     * @param response    HttpServletResponse
     * @param map         ModelMap
     * @param code        规则项编码
     * @param type        规则集类别： 普通 规则集 政策规则集
     * @param fromGeneral 从普通规则中选取的规则编号 “;”分割
     * @return 批量添加结果信息
     */
    @RequestMapping("addRuleItemFromGeneralAction")
    public @ResponseBody
    ResponseVO addRuleItemFromGeneralAction(@RequestBody RuleGroupInfo ruleGroupInfo) throws Exception {
        if (StringUtils.isEmpty(ruleGroupInfo.getManageId())) {
            throw new BizException("请求缺少manageId");
        }
        RuleGroupRef returnData = this.ruleGroupService.addGroupRuleFromGerneal(ruleGroupInfo.getFromGeneral(), ruleGroupInfo.getManageId(),ruleGroupInfo.getEntryId());
        DataCache.ruleRefEntryGroupChange(ruleGroupInfo.getProjectCode());//清理缓存
        ResponseVO res = new ResponseVO();
       	res.setData(returnData);
        res.setStatus(ResponseVO.OK);
        return res;
    }
    // --- 以上是vue 引用规则添加的方法
    /**
     * 版本管理方法：规则集版本选择
     *
     * @param versioninfo 版本请求信息
     * @return JSP路径
     */
    @RequestMapping("selectRuleSetVersion")
    public ResponseTable<RuleVersioninfo> selectRuleSetVersion(@RequestBody RuleVersioninfo versioninfo) throws Exception {
        List<RuleVersioninfo> list = this.ruleVersioninfoService.findList(versioninfo);
        PageInfo<RuleVersioninfo> pageinfo = new PageInfo<>(list);
        ResponseTable<RuleVersioninfo> res = new ResponseTable(pageinfo);
        return res;
    }

    @RequestMapping("returnRuleSetVersion")
    @ResponseBody
    public JsonMessage returnRuleSetVersion(String manageId, String oldVersion) {
        JsonMessage retMsg = new JsonMessage();
        retMsg.setResult(true);
        retMsg.setMessage("保存成功！");
        if (StringUtils.isEmpty(manageId) || StringUtils.isEmpty(oldVersion)) {
            retMsg.setResult(false);
            return retMsg;
        }
        try {
            this.ruleGroupService.returnRuleSetVersion(manageId, oldVersion);
        } catch (BizException e) {
            retMsg.setResult(false);
            retMsg.setMessage(e.getMessage());
        } catch (Exception e) {
			e.printStackTrace();
		}
        return retMsg;
    }

    /**
     * 规则集本身复制
     */
    @RequestMapping("copyRule")
    public @ResponseBody ResponseVO copyRule(@RequestBody ProjectInfo  projectInfo) {
    	ResponseVO ret = new ResponseVO();
    	ret.setStatus(ResponseVO.OK);
        try {
            this.ruleGroupService.copyRuleGroup(projectInfo);
        } catch (Exception e) {
            e.printStackTrace();
            ret.setDescription(e.getMessage());
            ret.setStatus(ResponseVO.ERROR);
        }
        return ret;
    }

    /**
     * 简易规则集中复制规则
     */
    @RequestMapping("copyRuleItem")
    public @ResponseBody ResponseVO copyRuleItem(@RequestBody RuleGroupInfo ruleGroupInfo) throws Exception {
    	ResponseVO ret = new ResponseVO();
    	ret.setStatus(ResponseVO.OK);
        try {
            this.ruleGroupService.copyRuleItem(ruleGroupInfo);
        } catch (Exception e) {
            e.printStackTrace();
            ret.setDescription(e.getMessage());
            ret.setStatus(ResponseVO.ERROR);
        }
        return ret;
    }

    /**
     * 获取规则集or政策规则集列表
     */
    @RequestMapping("getruleGroupList")
    public String getruleGroupList(String type, String currCode, String sourceRuleId, String manageId,ModelMap map) throws Exception {
        List<RuleManageVO> showList = this.ruleGroupService.findRuleGroupList(currCode, this.getCurrProjectCode());
        RuleManage ruleManage = this.ruleManageService.get(manageId);
        map.put("list", showList);
        map.put("sourceRuleId", sourceRuleId);
        map.put("sourceVersion", ruleManage.getVersion());
        map.put("sourceCode", currCode);
        map.put("type", type);
        return "rule/rulegroup/ruleset/ruleGroupList";
    }

    /**
     * 获取规则集or政策规则集列表
     */
    @RequestMapping("searchList")
    public String searchList(RuleManageVO param, ModelMap map, String sourceRulesId, String sourceCode, HttpServletRequest request) throws Exception {
        if (sourceRulesId == null) {
            sourceRulesId = request.getParameter("sourceRulesId");
        }
        param.setProjectCode(getCurrProjectCode());
        param.setModelType(RuleModelTypeEnum.PolicyRuleGroup.code);
        List<RuleManageVO> showList = this.ruleManageService.findRuleManageVO(param);
        RuleManageVO ruleManageVO = null;
        for (RuleManageVO tmpMamage : showList) {
            if (tmpMamage.getCode().equals(sourceCode)) {
                ruleManageVO = tmpMamage;
                break;
            }
        }
        showList.remove(ruleManageVO);
        map.put("list", showList);
        map.put("sourceRuleId", sourceRulesId);
        return "rule/rulegroup/ruleset/ruleGroupList";
    }

    /**
     * 转移规则
     */
    @RequestMapping("transferRuleItem")
    public @ResponseBody
    JsonMessage transferRuleItem(String type, String sourceRuleId, String sourceVersion,String targetCode) throws Exception {
        JsonMessage ret = new JsonMessage();
        try {
            this.ruleGroupService.transferRuleItem(sourceRuleId, sourceVersion,targetCode, this.getCurrProjectCode());
            ret.setMessage("转移成功");
        } catch (Exception e) {
            e.printStackTrace();
            ret.setResult(false);
            ret.setMessage(e.getMessage());
        }
        return ret;
    }

    @Override
    public void setRuleBizService() {
        super.setRuleBaseService(this.ruleGroupService);
    }

    /*******************************************************以下是简易规则集增加的方法***************************************************/

    /**
     * 查询规则集详情
     *
     * @param request  HttpServletRequest
     * @param response HttpServletResponse
     * @param map      ModelMap
     * @param code     规则项编码
     * @param type     规则集类别： 普通 规则集 政策规则集
     * @return ResponseTable
     */
    @RequestMapping("simpleRuleGroupDetail")
    public ResponseTable<RuleGroup> simpleRuleGroupDetail(@RequestBody RuleManageVO ruleManage) throws Exception {
    	String id = ruleManage.getId();
    	String version = ruleManage.getVersion();
    	String temp = ruleManage.getIsTemp();
    	String rankRelationId = ruleManage.getRankRelationId();
    	if (StringUtils.isEmpty(id)) {
            throw new BizException("ID为空");
        }
        //查询RuleManage
        Map<String, Object> parmMap = new HashMap<String, Object>();
        parmMap.put("id", id);
        List<RuleManageVO> vList = this.ruleManageService.findRuleManageVO(parmMap);
        if (vList == null || vList.isEmpty()) {
        	String projectCode = ruleManage.getProjectCode();
        	if(StringUtils.isEmpty(projectCode)) {
        		projectCode = this.getCurrProjectCode();
        	}
        	RuleManage tmp = ruleManageService.findByCode(id, projectCode);
        	if(tmp==null){
        		  throw new BizException("");
        	}else{
        		BeanUtils.copyProperties(ruleManage, tmp);
        	}
        }else{
        	ruleManage = vList.get(0);
        }
        //查询引用的ruleManage
        RuleGroup ruleGroup = new RuleGroup();
        ruleGroup.setManageId(ruleManage.getId());
        if (StringUtils.isEmpty(version)) {
            ruleGroup.setVersion(ruleManage.getVersion());
            if("1".equals(temp)) {
            	ruleGroup.setVersion(ruleManage.getActiveVersion());
    		}
        } else {
            ruleGroup.setVersion(version);
        }
        List<RuleGroup> ruleList = this.ruleGroupRefService.findRefRuleManage(ruleGroup);
        PageInfo<RuleGroup> pageInfo = new PageInfo<>();
        pageInfo = PageUtils.createSimglePageInfo(ruleList);
        ResponseTable<RuleGroup> res = new ResponseTable<>(pageInfo);
        return res;
    }
    //--- 以上是vue规则集使用的方法，打开规则集，查询详情

    /**
     * 简易规则集中打开规则页面
     *
     * @param request  HttpServletRequest
     * @param response HttpServletResponse
     * @param map      ModelMap
     * @param code     规则项编码
     * @param type     规则集类别： 普通 规则集 政策规则集
     * @param id       规则项Id
     * @return JSP路径
     */
    @RequestMapping("openSimpleRuleItemPage")
    public String openSimpleRuleItemPage(HttpServletRequest request, HttpServletResponse response, ModelMap map, String type, String id,String refId,String manageId,String rankRelationId) throws Exception {
        RuleGroup rv = this.ruleGroupService.get(id);
        if ("show".equals(type)) {
            map.put("operType", "show");
        } else {
            map.put("operType", "edit");
        }
        map.put("manageId", manageId);
        map.put("ruleGroupId", id);
        map.put("rv", rv);
        map.put("refId", refId);
        map.put("projectCode", this.getCurrProjectCode());
        map.put("rankRelationId", rankRelationId);
        return "rule/rulegroup/ruleset/newRuleItem";
    }

    /**
     * 版本管理方法： 保存复杂规则集到小版本
     *
     * @param request  HttpServletRequest
     * @param response HttpServletResponse
     * @param map      ModelMap
     * @param code     规则项编码
     * @param type     规则集类别： 简易规则集
     * @return 版本更新结果
     */
    @RequestMapping("saveOrUpdateRuleGroup")
    public @ResponseBody ResponseVO saveRuleGroup(@RequestBody RuleGroupInfo ruleGroupInfo) throws Exception {
    	ResponseVO res = new ResponseVO();
    	try {
    		RuleManage ruleManage = this.ruleGroupService.saveOrUpdateRuleGroup(ruleGroupInfo.getManageId());
    		res.setData(ruleManage);
    		res.setStatus(ResponseVO.OK);
        } catch (Exception e) {
        	RuleManage ruleManage = this.ruleManageService.get(ruleGroupInfo.getManageId());
        	logger.error(e.getMessage(), e);
        	res.setStatus(ResponseVO.ERROR);
        	res.setData(ruleManage);
        }
        return res;
    }

    /**
     * 版本管理方法： 保存简易规则集到小版本
     *
     * @param request  HttpServletRequest
     * @param response HttpServletResponse
     * @param map      ModelMap
     * @param code     规则项编码
     * @param type     规则集类别： 简易规则集
     * @return 版本更新结果
     */
    @RequestMapping("saveSimpleRuleGroup")
    public @ResponseBody
    ResponseVO saveSimpleRuleGroup(@RequestBody RuleGroupInfo ruleGroupInfo) throws Exception {
    	ResponseVO res = new ResponseVO();
    	try {
        	this.ruleGroupService.saveOrUpdateSimpleRuleGroup(ruleGroupInfo.getManageId());
        } catch (Exception e) {
        	logger.error(e.getMessage(), e);
        	res.setStatus(ResponseVO.ERROR);
        }
    	res.setStatus(ResponseVO.OK);
        return res;
    }

    /**
     * 通过转换器将页面配置转换成java文本 show rule item java
     *
     * @param request  HttpServletRequest
     * @param response HttpServletResponse
     * @param map      ModelMap
     * @return Java文本
     */
    @RequestMapping("showJavaCode")
    public @ResponseBody
    ResMessage showJavaCode(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject json) throws Exception {
        ResMessage res = new ResMessage();
        String javacode = this.ruleGroupService.showRuleJava(json.getString("manageId"));
        res.setCode("success");
        res.setMsg(javacode);
        return res;
    }
}
